package utils;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.support.v4.content.ContextCompat;
import android.widget.TextView;

/**
 * Created by ltx on 17/8/11
 */

public class TextViewUtils {
    public static final int S_LEFT=0;
    private static final int S_TOP=1;
    private static final int S_RIGHT=2;
    private static final int S_BOTTOM=3;
    /**
     * 设置TextView DrableLeft 或者top bottom right
     * @param mContext context
     * @param mDrableRes 资源
     * @param mTv view
     * @param mType 方向
     */
    public static void setTextViewDrable(Context mContext, int mDrableRes, TextView mTv, int mType){
        Drawable drawable= ContextCompat.getDrawable(mContext,mDrableRes);
/// 这一步必须要做,否则不会显示.
        drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
        switch (mType){
            case S_LEFT:
                mTv.setCompoundDrawables(drawable,null,null,null);
                break;

            case S_TOP:
                mTv.setCompoundDrawables(null,drawable,null,null);
                break;

            case S_RIGHT:
                mTv.setCompoundDrawables(null,null,drawable,null);

                break;
            case S_BOTTOM:
                mTv.setCompoundDrawables(null,null,null,drawable);

                break;
        }
    }
}
